<?php

class IdGen
{
	static function generate()
	{
		return "x".time().rand();
	}
}

class Hideable
{
	public $id='';
	public $block=false;
	public $switch=false;
	public $hidden=false;

	function __construct($block=false,$switch=false,$shown=false)
	{
		$this->id=IdGen::generate();
		$this->block=$block;
		$this->switch=$switch;
		$this->hidden=!$shown;
	}

	function hidefunc()
	{
	  return "jeng_hide('".$this->id."',".($this->block?"1":"0").");";
	}
	
	function showfunc()
	{
	  return "jeng_show('".$this->id."',".($this->block?"1":"0").");";
	}
	
	function switchfunc()
	{
	  return "jeng_switch('".$this->id."',".($this->block?"1":"0").");";
	}
	
	function shield($str)
	{
		return str_replace("'","\'",$str);
	}
	
	function render_start()
	{
		$str=sprintf('<div id="%s"',$this->id);
		if ($this->hidden)
		{
			$str.=sprintf(' style="visibility: hidden;');
			if ($this->block)
			  $str.=" display: none;";
			$str.='"';
		}
		if (!$this->switch)
			$str.=sprintf(' onmouseover="%s" onmouseout="%s"',$this->showfunc(),$this->hidefunc());	
		$str.=">";
		return $str;
	}
	
	function render_end()
	{
	  return "</div>";
	}
	
	function render($body)
	{
		return $this->render_start().$body.$this->render_end();
	}
	static function srender($body,$block=false,$switch=false,$shown=false)
	{
		$x=new Hideable($block,$switch,$shown);
		return $x->render($body);
	}
}

?>